package com.huike.web.controller.report;

import java.util.List;
import java.util.Map;


import com.huike.contract.domain.ChannelStatistics;
import com.huike.report.domain.vo.CluesStatisticsVo;
import com.huike.report.domain.vo.SubjectStatisticsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.huike.clues.domain.TbActivity;
import com.huike.clues.domain.TbClue;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.contract.domain.TbContract;
import com.huike.report.domain.vo.ActivityStatisticsVo;
import com.huike.report.service.IReportService;


@RestController
@RequestMapping("/report")
public class ReportController extends BaseController {

    @Autowired
   private IReportService reportService;

    /**
     * 销售统计报表   归属渠道
     * @param beginCreateTime
     * @param endCreateTime
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("channelStatisticsList/{beginCreateTime}/{endCreateTime}")
    public TableDataInfo getChannelStatisticsList(@PathVariable String beginCreateTime,
                                               @PathVariable String endCreateTime,
                                               Integer pageNum,Integer pageSize){

        List<ChannelStatistics> list=reportService.getChannelStatisticsList(beginCreateTime,endCreateTime,pageNum,pageSize);
        Long total=reportService.getTotal(beginCreateTime,endCreateTime);
        TableDataInfo dataTable = getDataTable(list);
        dataTable.setTotal(total);
        return dataTable;
    }


    /**
     * 查询活动管理列表
     */
    //@ApiOperation("客户统计报表")
    @GetMapping("/contractStatisticsList")
    public TableDataInfo contractStatisticsList(TbContract contract){
        startPage();
        List<TbContract> list= reportService.contractReportList(contract);
        return getDataTable(list);
    }




    /**
     * 线索统计报表
     * @param clue
     * @return
     */
    @GetMapping("/cluesStatisticsList")
    public TableDataInfo cluesStatisticsList(TbClue clue){
        startPage();
        List<TbClue> list= reportService.cluesStatisticsList(clue);
        return getDataTable(list);
    }
    @GetMapping("/cluesStatistics/{beginCreateTime}/{endCreateTime}")
    public CluesStatisticsVo cluesStatistics(@PathVariable String beginCreateTime,
                                             @PathVariable String endCreateTime){
        return reportService.cluesStatistics(beginCreateTime,endCreateTime);
    }



    /**
     * 活动渠道统计
     * @param activity
     * @return
     */
    @GetMapping("/activityStatisticsList")
    public TableDataInfo activityStatisticsList(TbActivity activity) {
        List<ActivityStatisticsVo> list= reportService.activityStatisticsList(activity);
        return getDataTablePage(list);
    }

    @GetMapping("/subjectStatistics/{beginCreateTime}/{endCreateTime}")
    public AjaxResult subjectStatistics(@PathVariable String beginCreateTime,
                                        @PathVariable String endCreateTime){
//        List<Map<String,Object>> list = reportService.subjectStatistics(beginCreateTime,endCreateTime);
        List<SubjectStatisticsVo> list = reportService.subjectStatistics(beginCreateTime,endCreateTime);
        return AjaxResult.success(list);
    }

    @GetMapping("/deptStatisticsList/{beginCreateTime}/{endCreateTime}")
    public TableDataInfo getDeptStatisticsList(@PathVariable("beginCreateTime") String beginCreateTime, @PathVariable("endCreateTime") String endCreateTime,
                                               Integer pageNum, Integer pageSize){
        TableDataInfo tableDataInfo = new TableDataInfo(reportService.getDeptStatisticsList(beginCreateTime,endCreateTime,pageNum,pageSize),reportService.getDeptTotal(beginCreateTime,endCreateTime));
        tableDataInfo.setMsg("查询成功");
        tableDataInfo.setCode(200);
        return tableDataInfo;
    }
}
